package com.kayeah82.application.avatar.qq.component.impl;

import com.kayeah82.application.avatar.qq.component.SecurityService;
import com.kayeah82.application.avatar.qq.security.DefaultSecurityChain;
import com.kayeah82.application.avatar.qq.security.IPFrequencyFilter;
import com.kayeah82.application.avatar.qq.security.QQFrequencyFilter;
import com.kayeah82.application.avatar.qq.security.SecurityFilter;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author kayeah82
 * */
@Component
class SecurityServiceImpl implements SecurityService {

    private List<SecurityFilter> filters;

    public SecurityServiceImpl() {
        filters = new ArrayList<>();
    }

    @PostConstruct
    private void init() {
        filters.add(new IPFrequencyFilter());
        filters.add(new QQFrequencyFilter());
    }

    @Override
    public void authorize(HttpServletRequest request) {
        new DefaultSecurityChain(filters).doFilter(request);
    }

}
